package com.work.principle.component;

import com.work.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:DELL
 * Date:2025-06-24
 * Time:19:23
 */
//bean的生命周期
@Component
public class BeanLifeComponent implements BeanNameAware {
    private Dog singletonDog;//2.属性赋值

    //1.实例化
    public BeanLifeComponent(){
        System.out.println("执行构造函数...");
    }

    //2.属性赋值
    @Autowired
    public void setSingletonDog(Dog singletonDog) {
        this.singletonDog = singletonDog;
        System.out.println("执行setSingletonDog方法...");
    }

    //3.初始化--各种通知
    @Override
    public void setBeanName(String name) {
        System.out.println("setBeanName:"+name);
    }

    //3.初始化，用注解的方式
    @PostConstruct
    public void init(){
        System.out.println("执行PostConstruct方法...");
    }

    //4.使用Bean
    public void use(){
        System.out.println("执行use方法...");
    }

    //5.销毁。
    @PreDestroy
    public void destroy(){
        System.out.println("执行PreDestroy方法");
    }
}
